<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Result {
	public $code=-1;
	public $message='';
	public $data;
	
	public function setData($code,$message,$d){
		$this->code=$code;
		$this->message=urlencode($message);
		if(!empty($d)){
			if(is_object($d)){
				foreach($d as $n=>$v){
					$d->$n=urlencode($v);
				}
			}elseif(is_array($d)){ 
				$count=sizeof($d);
				for($i=0;$i<$count;$i++){
					foreach($d[$i] as $n=>$v){
						$d[$i]->$n=urlencode($v);
					}
				}			
			}
			$this->data=$d;
		}else{
			$this->data=null;
		}
		
	}
	
	public function output(){
		header("Content-Type:text/html;charset=utf8");
		echo urldecode(json_encode(array('code'=>$this->code,'message'=>$this->message,'data'=>$this->data)));
		//echo json_encode(array('code'=>$this->code,'message'=>$this->message,'data'=>$this->data));
	}
}
?>